import { _decorator, Component, director, instantiate, Node, Prefab } from 'cc';
import { SceneEnum } from '../Enum';
import { RendorManager } from '../Base/RendorManager';
import DataManger from '../RunTime/DataManager';
const { ccclass, property } = _decorator;

@ccclass('SceneManager')
export class SceneManager extends RendorManager {
    @property(Node)
    items: Node = null

    @property(Prefab)
    inventory: Prefab = null

    @property(Prefab)
    menu: Prefab = null

    type:SceneEnum
    
    start() {
        super.start()
        director.preloadScene(SceneEnum.H1)
        director.preloadScene(SceneEnum.H2)
        director.preloadScene(SceneEnum.H3)
        director.preloadScene(SceneEnum.H4)
        director.preloadScene(SceneEnum.H2A)
        if (this.inventory) {
            this.node.addChild(instantiate(this.inventory))
        }
        if (this.menu) {
            this.node.addChild(instantiate(this.menu))
        }
    }

    changeScene(e: Event, scene: string) {
        DataManger.Instance.curScene=scene as SceneEnum
        //director.loadScene(scene as SceneEnum)
    }

    rendor() {
        if (DataManger.Instance.curScene === this.type) {
            return
        }
        director.loadScene(DataManger.Instance.curScene)
    }
}


